
/**
 * 最大字节长度规则
 */
$.validator.addMethod("maxByte", function(value, element, param) {
	return $.trim(value).getBytesLength() <= param;
}, "字节长度超出");

/**
 * 最小字节长度规则
 */
$.validator.addMethod("minByte", function(value, element, param) {
	return $.trim(value).getBytesLength() >= param;
}, "字节长度太小");

/**
 * 字母与数字
 */
$.validator.addMethod("letterAndNumber", function(value, element, param) {
	var letter = /^[a-zA-Z0-9]+$/;
	value = $.trim(value);
	return letter.test(value);
}, "只能包含字母和数字");

/**
 * 二选一规则
 */
$.validator.addMethod("eitherOr", function(value, element, param) {
	value = $.trim(value);
	return value != "" || $(param).val() != "";
}, "二选一规则");

/**
 * 手机验证规则 // var mobile = /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/;
 */
$.validator.addMethod("mobile", function(value, element) {
	var mobile = /^[0-9]{11}$/;

	value = $.trim(value);
	var length = value.length;
	return this.optional(element) || (length == 11 && mobile.test(value));
}, "手机号码格式有误");

/**
 * 电话验证规则
 */
$.validator.addMethod("telephone", function(value, element) {
	var tel = /^(\d{3,4}-?)?\d{7,9}$/;

	value = $.trim(value);
	return this.optional(element) || (tel.test(value));
}, "电话格式有误");

/**
 * 邮政编码验证规则
 */
$.validator.addMethod("code", function(value, element) {
	var code = /^[_0-9a-z]{1,20}$/i;

	value = $.trim(value);
	return this.optional(element) || (code.test(value));
}, "邮政编码格式有误");
